package com.jzr.bedside.presenter.impl

import android.content.Context
import com.jzr.bedside.api.Api
import com.jzr.bedside.base.BasePresenter
import com.jzr.bedside.bean.ConnectTestBean
import com.jzr.bedside.bean.OrderListBean
import com.jzr.bedside.bean.TemperatureBean
import com.jzr.bedside.bean.body.TemperatureAddBody
import com.jzr.bedside.presenter.contract.TemperatureActivityContract
import com.jzr.bedside.presenter.contract.TestActivityContract
import okhttp3.RequestBody
import rx.Observer
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

class TemperatureActivityImpl  : BasePresenter<TemperatureActivityContract.View>(),
    TemperatureActivityContract.Presenter<TemperatureActivityContract.View>{


    override fun getTemperatureAdd(context: Context?, query:  RequestBody?) {
        showLoadingDialog(context)
        addSubscrebe(
            Api.getInstance()?.getTemperatureAdd(query)
                ?.observeOn(AndroidSchedulers.mainThread())
                ?.subscribeOn(Schedulers.io())
                ?.unsubscribeOn(Schedulers.io())
                ?.subscribe(object : Observer<TemperatureBean?> {
                    override fun onCompleted() {}
                    override fun onError(e: Throwable) {
                        dismissLoadingDialog()
                        if (mView != null) mView?.showError("连接失败")
                    }

                    override fun onNext(t: TemperatureBean?) {
                        dismissLoadingDialog()
                        if (mView != null && t != null ) {
                            mView?.getTemperatureAddSuccess(t)
                        } else {
                            mView?.showError("连接失败")
                        }
                    }
                })
        )
    }


}